package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


//说明这个Servlet是没有序列号的
@SuppressWarnings("serial")
//说明这个Servlet的名称是ajaxRequest，其地址是/ajaxRequest
//这与在web.xml中设置是一样的

public class Serverlet extends HttpServlet {  //需要继承HttpServlet  并重写doGet  doPost方法
    public Serverlet() {
        super();
        i=0;
    }
    protected String addjson(String old,String key,String val)
    {
        if(!old.equals(""))old=old+",";
        old=old+"\""+key+"\":\""+val+"\"";
        return old;
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws  IOException, ServletException {
        //doPost(request, response);  //将信息使用doPost方法执行   对应jsp页面中的form表单中的method
    }
    int i;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        response.setContentType("text/html;charset=UTF-8");
        response.setContentType("text/html");
        String question=request.getParameter("que");;//问题
//        boolean isSubmit=false;
        // 请求中文乱码处理
        String ans="huida:"+question;
        PrintWriter out = response.getWriter();
        String answer="";
        answer=addjson(answer,"ans0",ans+"0");
        answer=addjson(answer,"ans1",ans+"1");
        answer=addjson(answer,"ans2",ans+"2");
        answer=addjson(answer,"ans3",ans+"3");
        answer=addjson(answer,"ans4",ans+"4");
        answer=addjson(answer,"ans5",ans+"5");
        //接收参数
        answer="{"+answer+"}";
        out.print(answer);
        System.out.println(ans);

    }


}